<template>
  <div class="produce-model-dialog">
    <el-dialog v-model="drawerVisibleDetail" :destroy-on-close="true" :title="`车型信息`" width="96%" draggable align-center>
      <el-scrollbar height="100%">
        <div class="produce-model">
          <div class="produce-model-info">
            <div class="produce-model-info-left">
              <img :src="`${detailData.picture}`" />
              <div class="p">
                <span class="b-f mle">{{ setInfo(detailData.name) }}</span>
                <p>
                  <span class="b-t mb2 mt10">品牌</span>
                  <span class="b-f">AiTEN</span>
                </p>
                <p>
                  <span class="b-t mb2">类型</span>
                  <span class="b-f">{{ getDictItem("productId", detailData.typeId) }}</span>
                </p>
              </div>
            </div>
            <div class="produce-model-info-right">
              <span class="b-t">车型特点</span>
              <span class="b-c mt10"> {{ setInfo(detailData.remark) }} </span>
            </div>
          </div>
          <div class="produce-model-item mt30" v-for="(item, index) in detailData.propertyList" :key="`cs_${index}`">
            <div class="produce-model-item-title">
              <span class="b-f">{{ item.name }}</span>
            </div>
            <div class="produce-model-item-content">
              <div class="group-item" v-for="(itm, idx) in item.children" :key="`${idx}_${item.id}`">
                <span>{{ itm.title }}</span>
                <span v-if="!itm.type">
                  <template v-if="Array.isArray(itm.value)">
                    <i v-for="(val, i) in itm.value" :key="i + 'sfr'">{{ val }}</i>
                  </template>
                  <i v-else>{{ itm.value }}</i>
                </span>
                <span v-else>
                  <a @click="imageHandle(itm.value)" style="cursor: pointer">{{ !itm.value ? "--" : "查看" }}</a>
                </span>
              </div>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </el-dialog>
    <el-image-viewer v-if="imgViewVisible" :url-list="[`${url}`]" @close="imgViewVisible = false" />
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useDetail } from "./hooks/useDetail";
import { useDict } from "@/hooks/useDict";
const drawerVisibleDetail = defineModel("drawerVisibleDetail", {
  type: Boolean,
  default: false
});
const props = defineProps({
  id: {
    type: String,
    default: ""
  }
});
const imgViewVisible = ref(false);
const url = ref("");
// hook
const { detailData } = useDetail({ id: props.id });
const { getDictItem } = useDict(["productId"]);
// 方法
const imageHandle = val => {
  if (!val) return;
  imgViewVisible.value = true;
  url.value = val;
};
const setInfo = (data: string) => {
  return data || "--";
};
</script>
<style lang="scss" scoped>
.b-f {
  font-size: 16px;
  font-weight: 600;
  color: #333333;
}
.b-t {
  font-size: 16px;
  font-weight: 400;
  color: #999999;
}
.b-c {
  font-size: 14px;
  font-weight: 400;
  color: #333333;
}
.produce-model {
  height: 70vh;
  padding: 40px;
  &-info {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    height: 269px;
    padding: 30px;
    border: 1px solid #f3f3f3;
    &-left {
      display: flex;
      flex: 0 0 460px;
      img {
        width: 200px;
        height: 200px;
        margin-right: 22px;
        background-color: #f3f3f3;
      }
      .p {
        display: grid;
        grid-template-rows: 1fr 1fr 1fr;
        width: 100%;
        p {
          display: flex;
          flex-flow: column nowrap;
          padding: 0;
          margin: 0;
        }
      }
    }
    &-right {
      display: flex;
      flex: 1;
      flex-flow: column nowrap;
    }
  }
  &-item {
    &-title {
      box-sizing: border-box;
      height: 60px;
      padding: 20px;
      font-size: 14px;
      font-weight: 600;
      color: #333333;
      border: 1px solid #f3f3f3;
    }
    &-content {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      .group-item:nth-child(2n) {
        border-right: none;
        border-left: none;
      }
    }
  }
  .group-item {
    display: flex;
    align-items: center;
    height: 64px;
    border: 1px solid #f3f3f3;
    border-top: none;
    span:first-child {
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      padding: 0 20px;
      line-height: 64px;
      text-align: right;
      background: #f5f7fa;
      border-right: 1px solid #f3f3f3;
    }
    a {
      color: $primary-color;
      cursor: pointer;
    }
    span:last-child {
      box-sizing: border-box;
      display: flex;
      flex-flow: column nowrap;
      justify-content: center;
      width: 100%;
      height: 100%;
      padding: 0 20px;
      overflow: auto;
      font-size: 14px;
      font-weight: 400;
      line-height: 20px;
      color: #333333;
      text-align: left;
      i {
        font-style: normal;
        text-align: left;
      }
    }
  }
}
</style>
